import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import dts from "vite-plugin-dts";
import { resolve } from "path";
import tailwindcss from "tailwindcss";
import autoprefixer from "autoprefixer";
// https://vitejs.dev/config/
export default defineConfig({
  base: "./",
  resolve: {
    alias: {
      assets: resolve(__dirname, "./src/assets"),
      _common: resolve(__dirname, "./src/_common"),
      components: resolve(__dirname, "./src/components"),
      configs: resolve(__dirname, "./src/configs"),
      modules: resolve(__dirname, "./src/modules"),
      styles: resolve(__dirname, "./src/styles"),
      utils: resolve(__dirname, "./src/utils"),
      designer: resolve(__dirname, "./src/designer"),
      framework: resolve(__dirname, "./src/framework"),
      global: resolve(__dirname, "./src/global"),
      hooks: resolve(__dirname, "./src/hooks"),
    },
  },
  //{ rollupTypes: true } cssInjectedByJsPlugin()
  plugins: [react(), dts()],
  css: {
    postcss: {
      plugins: [tailwindcss, autoprefixer],
    },
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },
  build: {
    outDir: "lib",
    lib: {
      name: "EGodWebCore",
      //fileName: (format) => `index.${format}.js`,
      entry: resolve(__dirname, "src/index.ts"),
      // entry: "./src/index.ts",
      formats: ["es"],
      fileName: "index",
    },
    rollupOptions: {
      // 确保外部化处理你不想打包进库的依赖
      external: ["react", "react-dom"],
      output: {
        globals: {
          react: "React",
          "react-dom": "ReactDOM",
        },
      },
    },
  },
});
